﻿'*******************************************************************************************
'* Copyright Brügmann Software GmbH, Papenburg
'* Author: Björn Kremer
'* Contact: codeplex<at>patorg.de
'* 
'* VB.CMIS is a VB.NET implementation of the Content Management Interoperability Services (CMIS) standard
'*
'* This file is part of VB.CMIS.
'* 
'* VB.CMIS is free software: you can redistribute it and/or modify
'* it under the terms of the GNU Lesser General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'* 
'* VB.CMIS is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'* GNU Lesser General Public License for more details.
'* 
'* You should have received a copy of the GNU Lesser General Public License
'* along with VB.CMIS. If not, see <http://www.gnu.org/licenses/>.
'*******************************************************************************************
Imports System.Xml.Serialization
Imports System.Xml

Namespace CMISObjects
   <XmlRoot("content", Namespace:=CmisNamespaceConstants.Atom)>
   Public Class AtomContent
      Implements IXmlSerializable
      Public Sub New()

      End Sub

      Public Sub New(src As String, value As String, mediaType As String)
         _src = src
         _mediaType = mediaType
         _Value = value
      End Sub
      Private _src As String
      Public ReadOnly Property SRC As String
         Get
            Return _src
         End Get
      End Property
      Private _Value As String
      Public ReadOnly Property Value As String
         Get
            Return _Value
         End Get
      End Property
      Private _mediaType As String
      Public ReadOnly Property MediaType As String
         Get
            Return _mediaType
         End Get
      End Property


      Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema
         Return Nothing
      End Function

      Public Sub ReadXml(reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml
         Dim doc As New System.Xml.XmlDocument()
         doc.Load(reader)
         Dim node As XmlNode = Common.GetItemCaseInsensitiveFromXML(doc, Common.GetXMLRootName(GetType(ContentContainer)))
         For Each child As XmlAttribute In node.Attributes
            Dim lname As String = Common.GetNodeNameWithoutPrefix(child).ToLowerInvariant
            If lname.Equals("type") Then
               _mediaType = child.InnerText
            ElseIf lname.Equals("src") Then
               _src = child.InnerText
            End If
         Next
         _Value = node.InnerText
      End Sub

      Public Sub WriteXml(writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml
         writer.WriteAttributeString("type", CmisNamespaceConstants.Cmisra, Me.MediaType)
         If Not String.IsNullOrEmpty(Me.SRC) Then
            writer.WriteAttributeString("src", CmisNamespaceConstants.Cmisra, Me.SRC)
         End If
         If Not String.IsNullOrEmpty(Me.Value) Then
            writer.WriteValue(Me.Value)
         End If
      End Sub
   End Class
End Namespace